<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({
            async:false
        });
    </script>
    <style>
        .layui-input-block{
            width:300px;
        }
        #saName{
            margin-top:20px;
        }
    </style>
</head>
<body>
<form class="layui-form" id="checkForm">
    <input type="hidden" id="sid" name="schemeId"/>
    <div class="layui-form-item" id="saName">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" lay-verify="title" autocomplete="off" class="layui-input layui-disabled" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否通过</label>
        <div class="layui-input-block">
            <input type="checkbox" checked="" name="auditState" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择专家</label>
        <div class="layui-input-inline">
            <input type="hidden" name="expertName" id="expertName">
            <select name="expertId" lay-search="" id="expertId">
                <option value="">直接选择或搜索选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="opinion" name="auExp" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="formDemo" id="btn">立即提交</button>
        </div>
    </div>
</form>
<script>
    var form = null;
    var x = true;
    //开关
    layui.use(['form','jquery','layer'], function () {
        form = layui.form;
        var layedit = layui.layedit;
        var jquery = layui.jquery;
        var layer = layui.layer;
        findAllExpert();
        findBySeId();
        //监听指定开关
        form.on('switch(switchTest)', function(data){
            //专家不同意 必需要填审核意见
            x = this.checked;
            if(x==false){
                $("#opinion").attr("lay-verify","required");
                $("#expertId").attr("disabled","true");
                form.render();
            }else{
                $("#opinion").removeAttr("lay-verify");
                $("#expertId").removeAttr("disabled");
                form.render();
            }
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            var vs = $('select option:selected').val();
            $("#expertName").val(vs);
            /* layer.msg(JSON.stringify(data.field)); //弹出当前表单数据*/
            //自定义验证规则
                var formData = new FormData(document.getElementById("checkForm"));
                var url = "../../AtsSchemeActionNutrition/add";
                $.ajax({
                    type:"post",
                    url:url,
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        if(obj.num==1){
                            layer.msg(obj.msg,{icon:1,time:1000},function(){
                                //关闭当前层
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            });
                        }else{
                            //提示
                            layer.msg(obj.msg);
                        }
                    }
                })

            return false;
        });
    });

    //教练下拉列表框
    function findAllExpert(){
        var url = "../../AtsSchemeActionNutrition/findAllExpert";
        var data = null;
        $.post(url,data,function(obj){
            $.each(obj,function(index,item){
                console.info("我来了了了了来了"+item);
                $("#expertId").append("<option value='"+item.expertId+"'>"+item.expertName+"</option>");
            })
            //重新渲染
            form.render();
            //tableTwo.reload();//刷新表格
        },"json")
    }

    //专家咨询表 根据id查询
    function findBySeId(){
        var id = getQueryString("id");
        console.info(id);
        var url = "../../AtsSchemeActionNutrition/findBySeId";
        var data = {id:id};
        $.post(url,data,function(obj){
            $("#name").val(obj.saName);
            $("#sid").val(obj.schemeId);
            //重新渲染
            form.render();
        },"json")
    }
</script>
</body>
</html>